package com.fjrz.bbxwj.main.video.base

import android.os.Bundle
import android.view.View
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import com.blankj.utilcode.util.LogUtils
import com.fjrz.bbxwj.R
import com.fjrz.bbxwj.app.RZApplication
import com.fjrz.bbxwj.entity.User
import com.fjrz.bbxwj.entity.VideoList
import com.fjrz.bbxwj.main.host.side.MainUserInfoActivity
import com.scwang.smart.refresh.layout.api.RefreshLayout
import kotlinx.android.synthetic.main.activity_test_video.*
import rxhttp.wrapper.entity.Progress

class VideoUserFragment(private val mVideoLists: MutableList<VideoList>) : BaseVideoFragment() {

    companion object {
        private const val EXTRA_NAME_USER_ID = "EXTRA_NAME_USER_ID"
        private const val EXTRA_NAME_POSITION = "EXTRA_NAME_POSITION"
        fun newInstance(
            userId: Int, position: Int,
            videoLists: MutableList<VideoList>
        ): VideoUserFragment {
            val bundle: Bundle = Bundle().apply {
                putInt(EXTRA_NAME_USER_ID, userId)
                putInt(EXTRA_NAME_POSITION, position)
            }
            return VideoUserFragment(videoLists).apply { arguments = bundle }
        }
    }

    private val mUserId: Int
        get() = arguments?.getInt(EXTRA_NAME_USER_ID) ?: 0

    private val mPosition: Int
        get() = arguments?.getInt(EXTRA_NAME_POSITION) ?: 0

    override fun initData() {
        rvVideoBody.layoutManager
            ?.scrollToPosition(mPosition)
        mPlayerAdapter.mSelectPosition = mPosition
        mPlayerAdapter.setNewInstance(mVideoLists)
    }

    override fun setOnItemChildClickListener(videoList: VideoList, view: View, position: Int) {
        super.setOnItemChildClickListener(videoList, view, position)
        if (view.id == R.id.ivControlsHeads) {
            if (mUserId == videoList.user_id) {
                requireActivity().finish()
            } else {
                MainUserInfoActivity.open(
                    activity = requireActivity(),
                    user = videoList.user.apply { who = User.Who.USER_HE }
                )
            }
        }
    }
}